//
// Description: 345. 反转字符串中的元音字母
// Created by Loading on 2021/8/19.
//

#include <bits/stdc++.h>

using namespace std;

string reverseVowels(string s) {
    auto check = [](char c) {
        if (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u') {
            return true;
        }

        if (c == 'A' || c == 'E' || c == 'I' || c == 'O' || c == 'U') {
            return true;
        }

        return false;
    };

    int i = 0, j = (int) s.size() - 1;
    while (i < j) {
        while (i < s.size() && !check(s[i])) {
            ++i;
        }
        while (j >= 0 && !check(s[j])) {
            --j;
        }
        if (i < j) {
            swap(s[i], s[j]);
            ++i;
            --j;
        }
    }

    return s;
}

int main() {
    string s = "leetcode";
    string res = reverseVowels(s);
    cout << res << endl;
}